package org.darcy.controller.check;

import org.darcy.entity.CheckDelivery;
import org.darcy.framework.model.PageData;
import org.darcy.framework.model.PageParam;
import org.darcy.framework.model.R;
import org.darcy.service.check.CheckDeliveryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;

@Tag(name = "CheckDelivery接口：派工单")
@RestController
@RequestMapping(value = "/CheckDelivery")
@Slf4j
public class CheckDeliveryController {

	private final String info_prefix = "[派工单模块]";

	@Autowired
	private CheckDeliveryService checkDeliveryService;

	@Operation(summary = "派工单分页列表")
	@PostMapping(value = "list")
	public R list(@RequestBody PageParam<CheckDelivery> param) {
		log.debug("{}-列表数据", info_prefix);
		PageData<CheckDelivery> data = checkDeliveryService.page(param);
		return R.ok().data(data);
	}

	@Operation(summary = "派工单详情")
	@GetMapping("/view")
	public R view(Integer id) {
		log.debug("{}-查看派工单信息", info_prefix);
		CheckDelivery data = checkDeliveryService.getDetail(id);
		return R.ok().data(data);
	}

	@Operation(summary = "新增派工单")
	@PostMapping("add")
	public R add(@RequestBody CheckDelivery record) {
		log.debug("{}-新增CheckDelivery: {}", info_prefix, record);
		checkDeliveryService.insert(record);
		return R.ok("新增成功").data(record);
	}

	@Operation(summary = "根据ID删除派工单")
	@PostMapping("/del/{id}")
	public R del(@PathVariable Integer id) {
		log.debug("{}-根据ID删除", info_prefix, id);
		checkDeliveryService.delete(id);
		return R.ok("删除成功");
	}

	@Operation(summary = "更新派工单")
	@PostMapping("update")
	public R update(@RequestBody CheckDelivery record) {
		log.debug("{}-保存信息: {}", info_prefix, record);
		CheckDelivery data = checkDeliveryService.updateFlow(record);
		return R.ok("更新成功").data(data.getIsCommit());
	}

	@Operation(summary = "查看派工单属性")
	@GetMapping("/model")
	public CheckDelivery model() {
		return null;
	}

}
